package com.fimmlps.reronge.dto;

import com.fimmlps.reronge.entity.EntrySingle;
import com.fimmlps.reronge.entity.EntryUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class EntrySingleDto {
    //作为百科页面的词条完整内容，包含词条全部信息及其所有Trigger
    //id ID
    private long entrySingleId;

    //title 标题
    private String title;

    //resume 摘要
    private String resume;

    private String description;

    private String htmlContent;

    //creator id
    private long creatorId;
    private String creator;

    //最后修改时间
    private LocalDateTime updateTime;

    //点击量
    private long clicks;

    //是否已收藏
    private boolean collected;

    //triggers
    private List<EntryTriggerDto> triggers;

    //usages
    private List<EntryUsageDto> usages;

    //contents 第一层的评论，特点是entryCommentTopId为-1或null（代表无根评论）
    private List<EntryCommentDto> comments;

    public EntrySingleDto(EntrySingle single){
        entrySingleId = single.getEntrySingleId();
        title = single.getTitle();
        resume = single.getResume();
        description = single.getDescription();
        htmlContent = single.getHtmlContent();
        updateTime = single.getUpdateTime();
        clicks = single.getClicks();
        triggers = new ArrayList<>();
        usages = new ArrayList<>();
        comments = new ArrayList<>();
    }

    public EntrySingleDto(EntrySingle single, EntryUser user){
        this(single);
        creatorId = user.getUserId();
        creator = user.getUserName();
    }

    public EntrySingleDto(EntrySingle single,List<EntryTriggerDto> dtoList){
        this(single);
        this.triggers = dtoList;
    }
}
